package net.northcoding.fresh.util;
// @Author Diamond - Administrator
// @Date 2023/12/8 11:26:35

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class ConsoleUtil {
    private static Map<color, Integer> fcolors; // font color
    private static Map<color, Integer> bcolors; // background color
    private static Map<font, Integer> fonts;

    static {
        fcolors = new HashMap<>();
        fcolors.put(color.RED, 31);
        fcolors.put(color.GREEN, 32);
        fcolors.put(color.YELLOW, 33);
        fcolors.put(color.BLUE, 34);
        fcolors.put(color.PURPLE, 35);
        fcolors.put(color.CYAN, 36);
        fcolors.put(color.GRAY, 37);
        fcolors.put(color.WHITE, 97);
        bcolors = new HashMap<>();
        bcolors.put(color.RED, 41);
        bcolors.put(color.GREEN, 42);
        bcolors.put(color.YELLOW, 43);
        bcolors.put(color.BLUE, 44);
        bcolors.put(color.PURPLE, 45);
        bcolors.put(color.CYAN, 46);
        bcolors.put(color.GRAY, 47);
        bcolors.put(color.BLACK, 40);
        fonts = new HashMap<>();
        fonts.put(font.RESET, 0);
        fonts.put(font.BOLD, 1);
        fonts.put(font.LESS, 2);
        fonts.put(font.VAR, 3);
        fonts.put(font.UNDERLINE, 4);
        fonts.put(font.FAST_LIGHT, 5);
        fonts.put(font.SLOW_LIGHT, 6);
    }

    public static String getColoredString(int color, int fontType, String content) {
        return String.format("\033[%d;%dm%s\033[0m", color, fontType, content);
    }

    public static String getColoredString(color c, boolean isBackgroundColor, font f, String content) {
        int color2;
        if (isBackgroundColor) color2 = bcolors.get(c);
        else color2 = fcolors.get(c);
        int font = fonts.get(f);
        return getColoredString(color2, font, content);
    }

    public static String getTime() {
        Date date = new Date(System.currentTimeMillis());
        // 处理日期转换
        SimpleDateFormat dateFormat = new SimpleDateFormat("[yyyy/MM/dd HH:mm:ss]");
        return dateFormat.format(date);// 2023/12/8 12:11:12
    }

    public enum color {
        RED,
        GREEN,
        YELLOW,
        BLUE,
        PURPLE,
        CYAN,
        GRAY,
        WHITE,
        BLACK
    }

    public enum font {
        RESET,
        BOLD,
        LESS,
        VAR,
        UNDERLINE,
        SLOW_LIGHT,
        FAST_LIGHT
    }
}
